<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>GPS on Google Maps</title>

    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAADJiKn6BRdHsk7vWE6-nZQBTdbh-XA1vG_2va-t_R_d5HiD7XoBQo6slTpvcoFDiIDj3JW5uZFBywbg"
      type="text/javascript"></script>
    <script type="text/javascript">

    //<![CDATA[
	
	function initXMLHttp(){
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlhttp = false;
			}
		}
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest();
		}
		if(!xmlhttp) alert("Can't' initzialize the XMLHttp object.");
	}

	var xmlhttp = false;
	initXMLHttp();
	
	var map = false;
	var marker = false;
		
	function init(){
		var coord = xmlhttp.responseText.split("\n");
		lat = parseFloat(coord[0]);
		lon = parseFloat(coord[1]);
		
		map = new GMap2(document.getElementById("map"));
		var center = new GLatLng(lat, lon);
		map.setCenter(new GLatLng(0, 0), 15);

		marker = new GMarker(center, {draggable: true});
		map.addOverlay(marker);

        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.enableContinuousZoom();

	}

	function updateGPS(){
		xmlhttp.open("GET", "/tmp/gps", true); // uso una named pipe?
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				var coord = xmlhttp.responseText.split("\n");
				lat = parseFloat(coord[0]);
				lon = parseFloat(coord[1]);
				
				var center = new GLatLng(lat, lon);
				map.panTo(center);
				marker.setLatLng(center);
			}
		}
		xmlhttp.send(null)
		setTimeout('updateGPS()', 1000);
	}

	function load() {
		if (GBrowserIsCompatible()) {
			init();
			updateGPS();
		}
	}
	
    //]]>
    </script>
  </head>
  <body id="body" onload="load()" onunload="GUnload()">
    <div id="map" style="width: 500px; height: 300px"></div>
  </body>
</html>